package com.lzz.controller;

import com.lzz.entity.Role;
import com.lzz.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhenzhen
 * @date 2018-12-21 下午7:47
 */
@Controller
@RequestMapping(value = "/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping(value = "/addView")
    public String addRoleView() {
        return "addRole";
    }

    @PostMapping(value = "/addRole", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String addRole(Role role) {
        role.setAvailable(true);
        int result = roleService.addRole(role);
        return result == 1 ? "添加成功" : "添加失败";
    }

    @GetMapping(value = "/getRole/{uuid}", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Role getRoleById(@PathVariable String uuid) {
        return roleService.getRoleById(uuid);
    }
}
